import { Component, OnInit,ElementRef,Input,Output,ChangeDetectionStrategy } from '@angular/core';
import { BreadcrumbComponent } from './breadcrumb.component';
import { Router } from '@angular/router';
import { removeNgTag } from '../shared/utils/index';

@Component({
  selector: 'el-breadcrumb-item',
  templateUrl: './breadcrumb-item.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BreadcrumbItemComponent implements OnInit {
  root!: BreadcrumbComponent;
  private router:any;
  private el:any;
  @Input() to: string = '';
  @Input() prevent: boolean = false;
  extras?: any;
  constructor(root: BreadcrumbComponent, router: Router, el: ElementRef){
    this.root = root;
        this.router = router;
        this.el = el;
  };

  ngOnInit(): void {
    removeNgTag(this.el.nativeElement);
  }

  clickHandle(event: Event): any {
    event.stopPropagation()
    this.root.itemHandle(this.to)
    if (!this.to || this.root.prevent || this.prevent) return
    return this.router.navigateByUrl(this.to, this.extras)
  }
  
}
